package com.kgc.onlineLife.controller;

import com.kgc.onlineLife.bean.Review;
import com.kgc.onlineLife.service.ReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * Created On : 2022/4/15.
 * <p>
 * Author     : hi
 * <p>
 * Description: 评论
 */
@Controller
@RequestMapping("/Admin")
public class ReviewController {
    @Autowired
    private ReviewService reviewService;
/**
 * @author : hi
 * @date   : 2022/4/15
 * @param  : [javax.servlet.http.HttpServletRequest, java.util.Map<java.lang.String,java.lang.Object>]
 * @return : java.lang.String
 * @description : 查询所有评论
 */
@RequestMapping("/appraiseList")
    public String reviewList(HttpServletRequest request, Map<String,Object> map){
//获取查询参数
//String id = request.getParameter("id") == null?"0":request.getParameter("id");
    List<Review> reviewList = reviewService.queryReview();
    for(Review r:reviewList){
        System.out.println(r);
    }

    map.put("reviews",reviewList);


return "Admin/appraise_list";
    }


    @RequestMapping(value = "/appraiseList/{id}" ,method = RequestMethod.DELETE)
    public String deleteReview(@PathVariable("id") Integer id){

    if (reviewService.delReview(id)){
        System.out.println("删除成功");
    }
        return "redirect:/Admin/appraiseList";
    }
@RequestMapping(value = "/appraiseList" ,method = RequestMethod.GET, params = "pname")
    public String selectReviewBypname (Map<String,Object>map,String pname){
    map.put("reviews",reviewService.queryReview(pname));

    return "Admin/appraise_list";
    }

}
